// leadtime报表显示工具类
export function drawChart(myChart, nameObj, series, formatter) {
  // 判断是否有数据
  var show = true
  if (series) {
    series.forEach(item => {
      item.data.forEach(data => {
        show = (show && data === null)
      })
    })
  }
  // 绘制图表
  myChart.setOption({
    title: {
      show: show,
      extStyle: {
        color: 'grey',
        fontSize: 20
      },
      text: '暂无数据',
      left: 'center',
      top: 'center'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {// 坐标轴指示器，坐标轴触发有效
        type: 'shadow'// 默认为直线，可选为：'line' | 'shadow'
      },
      formatter: formatter
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    legend: {
      data: nameObj.legend,
      show: (nameObj.legendShow === undefined || nameObj.legendShow === true)
    },
    xAxis: {
      name: nameObj.xName,
      type: 'category',
      data: nameObj.xNames,
      axisLabel: {
        interval: 0, // 横轴信息全部显示
        rotate: 25 // -15度角倾斜显示
      }
    },
    yAxis: {
      name: nameObj.yName,
      type: 'value',
      min: 0,
      max: function(value) {
        return (value.max * 1.2).toFixed(2)
      }
    },
    series: series
  })
  // document.getElementById('divFlag').style = 'display:block;font-size:16px;text-align:center;'
}

// 创建堆叠系列
export function createStackSerie(name, data, formatter) {
  return {
    name: name,
    type: 'bar',
    stack: '总量',
    label: {
      show: true,
      position: 'inside',
      formatter: formatter
    },
    data: data
  }
}

// 创建非堆叠系列
export function createSerie(name, data, formatter) {
  return {
    name: name,
    type: 'bar',
    label: {
      show: true,
      position: 'inside',
      formatter: formatter
    },
    data: data
  }
}
